home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / bone.zip / WEAPONS.QC < prev   
Text File  |  1996-08-31  |  29KB  |  1,362 lines

  1. /*
  2.  
  3. Throw the doggie a bone!     8/31/96 - Darin McNeil
  4.                            dhm7206@usl.edu
  5.  
  6. I adapted some of the launch code from patches by:
  7. Steve Bond
  8. Email: wedge@nuc.net    
  9. WWW: http://www.nuc.net/quake
  10.  
  11. Check his stuff out, it rules.
  12.  
  13. */
  14.  
  15. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  16. void () player_run;
  17. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  18. void(vector org, vector vel, float damage) SpawnBlood;
  19. void() SuperDamageSound;
  20.  
  21.  
  22. // called by worldspawn
  23. void() W_Precache =
  24. {
  25.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  26.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  27.     precache_sound ("weapons/sgun1.wav");
  28.     precache_sound ("weapons/guncock.wav"); // player shotgun
  29.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  30.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  31.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  32.     precache_sound ("weapons/spike2.wav");  // super spikes
  33.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  34.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  35.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  36.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  37.       precache_sound ("ohno.wav");    // Kim warning the dogs
  38.       precache_sound ("zombie/z_miss.wav");  //bone miss-bounce
  39.     precache_sound ("zombie/z_hit.wav");  //bone hit-bounce
  40. };
  41.  
  42. float() crandom =
  43. {
  44.     return 2*(random() - 0.5);
  45. };
  46.  
  47. /*
  48. ================
  49. W_FireAxe
  50. ================
  51. */
  52. void() W_FireAxe =
  53. {
  54.     local   vector  source;
  55.     local   vector  org;
  56.  
  57.     source = self.origin + '0 0 16';
  58.     traceline (source, source + v_forward*64, FALSE, self);
  59.     if (trace_fraction == 1.0)
  60.         return;
  61.     
  62.     org = trace_endpos - v_forward*4;
  63.  
  64.     if (trace_ent.takedamage)
  65.     {
  66.         trace_ent.axhitme = 1;
  67.         SpawnBlood (org, '0 0 0', 20);
  68.         T_Damage (trace_ent, self, self, 20);
  69.     }
  70.     else
  71.     {       // hit wall
  72.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  73.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  74.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  75.         WriteCoord (MSG_BROADCAST, org_x);
  76.         WriteCoord (MSG_BROADCAST, org_y);
  77.         WriteCoord (MSG_BROADCAST, org_z);
  78.     }
  79. };
  80.  
  81.  
  82. //============================================================================
  83.  
  84.  
  85. vector() wall_velocity =
  86. {
  87.     local vector    vel;
  88.     
  89.     vel = normalize (self.velocity);
  90.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  91.     vel = vel + 2*trace_plane_normal;
  92.     vel = vel * 200;
  93.     
  94.     return vel;
  95. };
  96.  
  97.  
  98. /*
  99. ================
  100. SpawnMeatSpray
  101. ================
  102. */
  103. void(vector org, vector vel) SpawnMeatSpray =
  104. {
  105.     local   entity missile, mpuff;
  106.     local   vector  org;
  107.  
  108.     missile = spawn ();
  109.     missile.owner = self;
  110.     missile.movetype = MOVETYPE_BOUNCE;
  111.     missile.solid = SOLID_NOT;
  112.  
  113.     makevectors (self.angles);
  114.  
  115.     missile.velocity = vel;
  116.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  117.  
  118.     missile.avelocity = '3000 1000 2000';
  119.     
  120. // set missile duration
  121.     missile.nextthink = time + 1;
  122.     missile.think = SUB_Remove;
  123.  
  124.     setmodel (missile, "progs/zom_gib.mdl");
  125.     setsize (missile, '0 0 0', '0 0 0');            
  126.     setorigin (missile, org);
  127. };
  128.  
  129. /*
  130. ================
  131. SpawnBlood
  132. ================
  133. */
  134. void(vector org, vector vel, float damage) SpawnBlood =
  135. {
  136.     particle (org, vel*0.1, 73, damage*2);
  137. };
  138.  
  139. /*
  140. ================
  141. spawn_touchblood
  142. ================
  143. */
  144. void(float damage) spawn_touchblood =
  145. {
  146.     local vector    vel;
  147.  
  148.     vel = wall_velocity () * 0.2;
  149.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  150. };
  151.  
  152.  
  153. /*
  154. ================
  155. SpawnChunk
  156. ================
  157. */
  158. void(vector org, vector vel) SpawnChunk =
  159. {
  160.     particle (org, vel*0.02, 0, 10);
  161. };
  162.  
  163. /*
  164. ==============================================================================
  165.  
  166. MULTI-DAMAGE
  167.  
  168. Collects multiple small damages into a single damage
  169.  
  170. ==============================================================================
  171. */
  172.  
  173. entity  multi_ent;
  174. float   multi_damage;
  175.  
  176. void() ClearMultiDamage =
  177. {
  178.     multi_ent = world;
  179.     multi_damage = 0;
  180. };
  181.  
  182. void() ApplyMultiDamage =
  183. {
  184.     if (!multi_ent)
  185.         return;
  186.     T_Damage (multi_ent, self, self, multi_damage);
  187. };
  188.  
  189. void(entity hit, float damage) AddMultiDamage =
  190. {
  191.     if (!hit)
  192.         return;
  193.     
  194.     if (hit != multi_ent)
  195.     {
  196.         ApplyMultiDamage ();
  197.         multi_damage = damage;
  198.         multi_ent = hit;
  199.     }
  200.     else
  201.         multi_damage = multi_damage + damage;
  202. };
  203.  
  204. /*
  205. ==============================================================================
  206.  
  207. BULLETS
  208.  
  209. ==============================================================================
  210. */
  211.  
  212. /*
  213. ================
  214. TraceAttack
  215. ================
  216. */
  217. void(float damage, vector dir) TraceAttack =
  218. {
  219.     local   vector  vel, org;
  220.     
  221.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  222.     vel = vel + 2*trace_plane_normal;
  223.     vel = vel * 200;
  224.  
  225.     org = trace_endpos - dir*4;
  226.  
  227.     if (trace_ent.takedamage)
  228.     {
  229.         SpawnBlood (org, vel*0.2, damage);
  230.         AddMultiDamage (trace_ent, damage);
  231.     }
  232.     else
  233.     {
  234.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  235.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  236.         WriteCoord (MSG_BROADCAST, org_x);
  237.         WriteCoord (MSG_BROADCAST, org_y);
  238.         WriteCoord (MSG_BROADCAST, org_z);
  239.     }
  240. };
  241.  
  242. /*
  243. ================
  244. FireBullets
  245.  
  246. Used by shotgun, super shotgun, and enemy soldier firing
  247. Go to the trouble of combining multiple pellets into a single damage call.
  248. ================
  249. */
  250. void(float shotcount, vector dir, vector spread) FireBullets =
  251. {
  252.     local   vector direction;
  253.     local   vector  src;
  254.     
  255.     makevectors(self.v_angle);
  256.  
  257.     src = self.origin + v_forward*10;
  258.     src_z = self.absmin_z + self.size_z * 0.7;
  259.  
  260.     ClearMultiDamage ();
  261.     while (shotcount > 0)
  262.     {
  263.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  264.  
  265.         traceline (src, src + direction*2048, FALSE, self);
  266.         if (trace_fraction != 1.0)
  267.             TraceAttack (4, direction);
  268.  
  269.         shotcount = shotcount - 1;
  270.     }
  271.     ApplyMultiDamage ();
  272. };
  273.  
  274. /*
  275. ================
  276. W_FireShotgun
  277. ================
  278. */
  279. void() W_FireShotgun =
  280. {
  281.     local vector dir;
  282.  
  283.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  284.  
  285.     self.punchangle_x = -2;
  286.     
  287.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  288.     dir = aim (self, 100000);
  289.     FireBullets (6, dir, '0.04 0.04 0');
  290. };
  291.  
  292.  
  293. /*
  294. ================
  295. W_FireSuperShotgun
  296. ================
  297. */
  298. void() W_FireSuperShotgun =
  299. {
  300.     local vector dir;
  301.  
  302.     if (self.currentammo == 1)
  303.     {
  304.         W_FireShotgun ();
  305.         return;
  306.     }
  307.         
  308.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  309.  
  310.     self.punchangle_x = -4;
  311.     
  312.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  313.     dir = aim (self, 100000);
  314.     FireBullets (14, dir, '0.14 0.08 0');
  315. };
  316.  
  317.  
  318. /*
  319. ==============================================================================
  320.  
  321. ROCKETS
  322.  
  323. ==============================================================================
  324. */
  325.  
  326. void()  s_explode1      =       [0,             s_explode2] {};
  327. void()  s_explode2      =       [1,             s_explode3] {};
  328. void()  s_explode3      =       [2,             s_explode4] {};
  329. void()  s_explode4      =       [3,             s_explode5] {};
  330. void()  s_explode5      =       [4,             s_explode6] {};
  331. void()  s_explode6      =       [5,             SUB_Remove] {};
  332.  
  333. void() BecomeExplosion =
  334. {
  335.     self.movetype = MOVETYPE_NONE;
  336.     self.velocity = '0 0 0';
  337.     self.touch = SUB_Null;
  338.     setmodel (self, "progs/s_explod.spr");
  339.     self.solid = SOLID_NOT;
  340.     s_explode1 ();
  341. };
  342.  
  343. void() T_MissileTouch =
  344. {
  345.     local float     damg;
  346.  
  347.     if (other == self.owner)
  348.         return;         // don't explode on owner
  349.  
  350.     if (pointcontents(self.origin) == CONTENT_SKY)
  351.     {
  352.         remove(self);
  353.         return;
  354.     }
  355.  
  356.     damg = 100 + random()*20;
  357.     
  358.     if (other.health)
  359.     {
  360.         if (other.classname == "monster_shambler")
  361.             damg = damg * 0.5;      // mostly immune
  362.         T_Damage (other, self, self.owner, damg );
  363.     }
  364.  
  365.     // don't do radius damage to the other, because all the damage
  366.     // was done in the impact
  367.     T_RadiusDamage (self, self.owner, 120, other);
  368.  
  369. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  370.     self.origin = self.origin - 8*normalize(self.velocity);
  371.  
  372.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  373.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  374.     WriteCoord (MSG_BROADCAST, self.origin_x);
  375.     WriteCoord (MSG_BROADCAST, self.origin_y);
  376.     WriteCoord (MSG_BROADCAST, self.origin_z);
  377.  
  378.     BecomeExplosion ();
  379. };
  380.  
  381.  
  382.  
  383. /*
  384. ================
  385. W_FireRocket
  386. ================
  387. */
  388. void() W_FireRocket =
  389. {
  390.     local   entity missile, mpuff;
  391.     
  392.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  393.     
  394.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  395.  
  396.     self.punchangle_x = -2;
  397.  
  398.     missile = spawn ();
  399.     missile.owner = self;
  400.     missile.movetype = MOVETYPE_FLYMISSILE;
  401.     missile.solid = SOLID_BBOX;
  402.       missile.flags = FL_ITEM; 
  403.         
  404. // set missile speed    
  405.  
  406.     makevectors (self.v_angle);
  407.     missile.velocity = aim(self, 1000);
  408.     missile.velocity = missile.velocity * 1000;
  409.     missile.angles = vectoangles(missile.velocity);
  410.     
  411.     missile.touch = T_MissileTouch;
  412.     
  413. // set missile duration
  414.     missile.nextthink = time + 5;
  415.     missile.think = SUB_Remove;
  416.  
  417.     setmodel (missile, "progs/missile.mdl");
  418.     setsize (missile, '0 0 0', '0 0 0');            
  419.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  420. };
  421.  
  422. /*
  423. ===============================================================================
  424.  
  425. LIGHTNING
  426.  
  427. ===============================================================================
  428. */
  429.  
  430. /*
  431. =================
  432. LightningDamage
  433. =================
  434. */
  435. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  436. {
  437.     local entity            e1, e2;
  438.     local vector            f;
  439.     
  440.     f = p2 - p1;
  441.     normalize (f);
  442.     f_x = 0 - f_y;
  443.     f_y = f_x;
  444.     f_z = 0;
  445.     f = f*16;
  446.  
  447.     e1 = e2 = world;
  448.  
  449.     traceline (p1, p2, FALSE, self);
  450.     if (trace_ent.takedamage)
  451.     {
  452.         particle (trace_endpos, '0 0 100', 225, damage*4);
  453.         T_Damage (trace_ent, from, from, damage);
  454.         if (self.classname == "player")
  455.         {
  456.             if (other.classname == "player")
  457.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  458.         }
  459.     }
  460.     e1 = trace_ent;
  461.  
  462.     traceline (p1 + f, p2 + f, FALSE, self);
  463.     if (trace_ent != e1 && trace_ent.takedamage)
  464.     {
  465.         particle (trace_endpos, '0 0 100', 225, damage*4);
  466.         T_Damage (trace_ent, from, from, damage);
  467.     }
  468.     e2 = trace_ent;
  469.  
  470.     traceline (p1 - f, p2 - f, FALSE, self);
  471.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  472.     {
  473.         particle (trace_endpos, '0 0 100', 225, damage*4);
  474.         T_Damage (trace_ent, from, from, damage);
  475.     }
  476. };
  477.  
  478.  
  479. void() W_FireLightning =
  480. {
  481.     local   vector          org;
  482.  
  483.     if (self.ammo_cells < 1)
  484.     {
  485.         self.weapon = W_BestWeapon ();
  486.         W_SetCurrentAmmo ();
  487.         return;
  488.     }
  489.  
  490. // explode if under water
  491.     if (self.waterlevel > 1)
  492.     {
  493.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  494.         self.ammo_cells = 0;
  495.         W_SetCurrentAmmo ();
  496.         return;
  497.     }
  498.  
  499.     if (self.t_width < time)
  500.     {
  501.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  502.         self.t_width = time + 0.6;
  503.     }
  504.     self.punchangle_x = -2;
  505.  
  506.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  507.  
  508.     org = self.origin + '0 0 16';
  509.     
  510.     traceline (org, org + v_forward*600, TRUE, self);
  511.  
  512.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  513.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  514.     WriteEntity (MSG_BROADCAST, self);
  515.     WriteCoord (MSG_BROADCAST, org_x);
  516.     WriteCoord (MSG_BROADCAST, org_y);
  517.     WriteCoord (MSG_BROADCAST, org_z);
  518.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  519.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  520.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  521.  
  522.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  523. };
  524.  
  525.  
  526. //=============================================================================
  527.  
  528.  
  529. void() GrenadeExplode =
  530. {
  531.     T_RadiusDamage (self, self.owner, 120, world);
  532.  
  533.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  534.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  535.     WriteCoord (MSG_BROADCAST, self.origin_x);
  536.     WriteCoord (MSG_BROADCAST, self.origin_y);
  537.     WriteCoord (MSG_BROADCAST, self.origin_z);
  538.  
  539.     BecomeExplosion ();
  540. };
  541.  
  542. void() GrenadeTouch =
  543. {
  544.     if (other == self.owner)
  545.         return;         // don't explode on owner
  546.     if (other.takedamage == DAMAGE_AIM)
  547.     {
  548.         GrenadeExplode();
  549.         return;
  550.     }
  551.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  552.     if (self.velocity == '0 0 0')
  553.         self.avelocity = '0 0 0';
  554. };
  555.  
  556. /*
  557. ================
  558. W_FireGrenade
  559. ================
  560. */
  561. void() W_FireGrenade =
  562. {
  563.     local   entity missile, mpuff;
  564.     
  565.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  566.     
  567.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  568.  
  569.     self.punchangle_x = -2;
  570.  
  571.     missile = spawn ();
  572.     missile.owner = self;
  573.     missile.movetype = MOVETYPE_BOUNCE;
  574.     missile.solid = SOLID_BBOX;
  575.     missile.classname = "grenade";
  576.         
  577. // set missile speed    
  578.  
  579.     makevectors (self.v_angle);
  580.  
  581.     if (self.v_angle_x)
  582.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  583.     else
  584.     {
  585.         missile.velocity = aim(self, 10000);
  586.         missile.velocity = missile.velocity * 600;
  587.         missile.velocity_z = 200;
  588.     }
  589.  
  590.     missile.avelocity = '300 300 300';
  591.  
  592.     missile.angles = vectoangles(missile.velocity);
  593.     
  594.     missile.touch = GrenadeTouch;
  595.     
  596. // set missile duration
  597.     missile.nextthink = time + 2.5;
  598.     missile.think = GrenadeExplode;
  599.  
  600.     setmodel (missile, "progs/grenade.mdl");
  601.     setsize (missile, '0 0 0', '0 0 0');            
  602.     setorigin (missile, self.origin);
  603. };
  604.  
  605.  
  606. //=============================================================================
  607.  
  608. void() spike_touch;
  609. void() superspike_touch;
  610.  
  611.  
  612. /*
  613. ===============
  614. launch_spike
  615.  
  616. Used for both the player and the ogre
  617. ===============
  618. */
  619. void(vector org, vector dir) launch_spike =
  620. {
  621.     newmis = spawn ();
  622.     newmis.owner = self;
  623.     newmis.movetype = MOVETYPE_FLYMISSILE;
  624.     newmis.solid = SOLID_BBOX;
  625.  
  626.     newmis.angles = vectoangles(dir);
  627.     
  628.     newmis.touch = spike_touch;
  629.     newmis.classname = "spike";
  630.     newmis.think = SUB_Remove;
  631.     newmis.nextthink = time + 6;
  632.     setmodel (newmis, "progs/spike.mdl");
  633.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  634.     setorigin (newmis, org);
  635.  
  636.     newmis.velocity = dir * 1000;
  637. };
  638.  
  639. void() W_FireSuperSpikes =
  640. {
  641.     local vector    dir;
  642.     local entity    old;
  643.     
  644.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  645.     self.attack_finished = time + 0.2;
  646.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  647.     dir = aim (self, 1000);
  648.     launch_spike (self.origin + '0 0 16', dir);
  649.     newmis.touch = superspike_touch;
  650.     setmodel (newmis, "progs/s_spike.mdl");
  651.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  652.     self.punchangle_x = -2;
  653. };
  654.  
  655. void(float ox) W_FireSpikes =
  656. {
  657.     local vector    dir;
  658.     local entity    old;
  659.     
  660.     makevectors (self.v_angle);
  661.     
  662.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  663.     {
  664.         W_FireSuperSpikes ();
  665.         return;
  666.     }
  667.  
  668.     if (self.ammo_nails < 1)
  669.     {
  670.         self.weapon = W_BestWeapon ();
  671.         W_SetCurrentAmmo ();
  672.         return;
  673.     }
  674.  
  675.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  676.     self.attack_finished = time + 0.2;
  677.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  678.     dir = aim (self, 1000);
  679.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  680.  
  681.     self.punchangle_x = -2;
  682. };
  683.  
  684.  
  685.  
  686. .float hit_z;
  687. void() spike_touch =
  688. {
  689. local float rand;
  690.     if (other == self.owner)
  691.         return;
  692.  
  693.     if (other.solid == SOLID_TRIGGER)
  694.         return; // trigger field, do nothing
  695.  
  696.     if (pointcontents(self.origin) == CONTENT_SKY)
  697.     {
  698.         remove(self);
  699.         return;
  700.     }
  701.     
  702. // hit something that bleeds
  703.     if (other.takedamage)
  704.     {
  705.         spawn_touchblood (9);
  706.         T_Damage (other, self, self.owner, 9);
  707.         remove(self);
  708.     }
  709.     else
  710.     {
  711.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  712.         
  713.         if (self.classname == "wizspike")
  714.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  715.         else if (self.classname == "knightspike")
  716.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  717.         else
  718.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  719.         WriteCoord (MSG_BROADCAST, self.origin_x);
  720.         WriteCoord (MSG_BROADCAST, self.origin_y);
  721.         WriteCoord (MSG_BROADCAST, self.origin_z);
  722.     }
  723.  
  724.     remove(self);
  725.  
  726. };
  727.  
  728. void() superspike_touch =
  729. {
  730. local float rand;
  731.     if (other == self.owner)
  732.         return;
  733.  
  734.     if (other.solid == SOLID_TRIGGER)
  735.         return; // trigger field, do nothing
  736.  
  737.     if (pointcontents(self.origin) == CONTENT_SKY)
  738.     {
  739.         remove(self);
  740.         return;
  741.     }
  742.     
  743. // hit something that bleeds
  744.     if (other.takedamage)
  745.     {
  746.         spawn_touchblood (18);
  747.         T_Damage (other, self, self.owner, 18);
  748.     }
  749.     else
  750.     {
  751.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  752.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  753.         WriteCoord (MSG_BROADCAST, self.origin_x);
  754.         WriteCoord (MSG_BROADCAST, self.origin_y);
  755.         WriteCoord (MSG_BROADCAST, self.origin_z);
  756.     }
  757.  
  758.     remove(self);
  759.  
  760. };
  761.  
  762.  
  763.  
  764.  
  765. /*  -----------
  766.     The old stuff a grenade in a piece of meat trick.
  767.     Dogs will stop whatever they are doing to get these tasty morsels.
  768.  
  769.     Darin McNeil - 8/31/96 - Quake rules the Cosmos!
  770.     dhm7206@usl.edu
  771.     ----------- */
  772.  
  773. void()  BoneExplode =
  774. {
  775.     
  776. // Do the damage
  777.     T_RadiusDamage (self, self.owner, 120, world);
  778. // Tell the network
  779.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  780.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  781.     WriteCoord (MSG_BROADCAST, self.origin_x);
  782.     WriteCoord (MSG_BROADCAST, self.origin_y);
  783.     WriteCoord (MSG_BROADCAST, self.origin_z);
  784.  
  785.     self.solid=SOLID_NOT;
  786.     BecomeExplosion ();
  787. };
  788.  
  789. // The Bone hit something, just bounce off.
  790. void() BoneTouch =
  791. {
  792.     if (other.takedamage)
  793.     {
  794.     sound (self, CHAN_WEAPON, "zombie/z_hit.wav", 1, ATTN_NORM);
  795.     return;
  796.     }
  797.     sound (self, CHAN_WEAPON, "zombie/z_miss.wav", 1, ATTN_NORM);
  798.     if (self.velocity == '0 0 0')
  799.         self.avelocity = '0 0 0';
  800. };
  801.  
  802. /*
  803. This spawns the bone and tosses it,
  804. it's a reworked copy of id's W_launchgrenade code.
  805. */
  806. void() W_LaunchBone =
  807. {
  808. // If player doesn't have 1 or more rockets, don't launch
  809.     if (self.ammo_rockets < 1)
  810.     {
  811.     return;
  812.     }
  813.  
  814.     local   entity missile, mpuff;
  815.     
  816. //dhm - Don't let the player throw bones too quickly
  817.       self.attack_finished = time + 0.6;
  818.  
  819. // Take 1 rocket from the player        
  820.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  821.     
  822.     sound (self, CHAN_WEAPON, "player/pain1.wav", 1, ATTN_NORM);
  823.     self.punchangle_x = -2;
  824.  
  825. // This spawns the bone - it is similar to id's standard grenade code        
  826.     missile = spawn ();
  827.     missile.owner = self;
  828.     missile.movetype = MOVETYPE_BOUNCE;
  829.     missile.solid = SOLID_SLIDEBOX; 
  830.           /* Interesting note: making the solid type - SOLID_SLIDEBOX - lets
  831.               the bone teleport.  This could have cool uses in later patches. 
  832.           I don't think it causes any undesirable side-effects.
  833.         */
  834.     missile.classname = "bone";
  835.         
  836. // set missile speed    
  837.  
  838.     makevectors (self.v_angle);
  839.  
  840.     if (self.v_angle_x)
  841.         missile.velocity = v_forward*300 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  842.     else
  843.     {
  844.         missile.velocity = aim(self, 10000);
  845.         missile.velocity = missile.velocity * 300;
  846.         missile.velocity_z = 200;
  847.     }
  848.  
  849.     missile.avelocity = '300 300 300';
  850.  
  851.     missile.angles = vectoangles(missile.velocity);
  852.  
  853. // dhm - if the bone touches anything, BoneTouch() is called        
  854.     missile.touch = BoneTouch;
  855.  
  856. // dhm - if the bone is chewed for awhile, it explodes!
  857.       missile.health = 30;
  858.       missile.th_die = BoneExplode;    
  859.     missile.takedamage= DAMAGE_AIM;
  860.  
  861. // set missile duration
  862.     missile.nextthink = time + 15;
  863.     
  864. // dhm - Remove the bone after it sits for awhile        
  865.     missile.think = SUB_Remove;
  866.  
  867.     setmodel (missile, "progs/zom_gib.mdl");
  868.     setsize (missile, '0 0 0', '0 0 0');            
  869.     setorigin (missile, self.origin);
  870. };
  871. // dhm - That's it for the Bone code.
  872.  
  873.  
  874.  
  875.  
  876.  
  877. /*
  878.  
  879. PLAYER WEAPON USE
  880.  
  881. ===============================================================================
  882. */
  883.  
  884. void() W_SetCurrentAmmo =
  885. {
  886.     player_run ();          // get out of any weapon firing states
  887.  
  888.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  889.     
  890.     if (self.weapon == IT_AXE)
  891.     {
  892.         self.currentammo = 0;
  893.         self.weaponmodel = "progs/v_axe.mdl";
  894.         self.weaponframe = 0;
  895.     }
  896.     else if (self.weapon == IT_SHOTGUN)
  897.     {
  898.         self.currentammo = self.ammo_shells;
  899.         self.weaponmodel = "progs/v_shot.mdl";
  900.         self.weaponframe = 0;
  901.         self.items = self.items | IT_SHELLS;
  902.     }
  903.     else if (self.weapon == IT_SUPER_SHOTGUN)
  904.     {
  905.         self.currentammo = self.ammo_shells;
  906.         self.weaponmodel = "progs/v_shot2.mdl";
  907.         self.weaponframe = 0;
  908.         self.items = self.items | IT_SHELLS;
  909.     }
  910.     else if (self.weapon == IT_NAILGUN)
  911.     {
  912.         self.currentammo = self.ammo_nails;
  913.         self.weaponmodel = "progs/v_nail.mdl";
  914.         self.weaponframe = 0;
  915.         self.items = self.items | IT_NAILS;
  916.     }
  917.     else if (self.weapon == IT_SUPER_NAILGUN)
  918.     {
  919.         self.currentammo = self.ammo_nails;
  920.         self.weaponmodel = "progs/v_nail2.mdl";
  921.         self.weaponframe = 0;
  922.         self.items = self.items | IT_NAILS;
  923.     }
  924.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  925.     {
  926.         self.currentammo = self.ammo_rockets;
  927.         self.weaponmodel = "progs/v_rock.mdl";
  928.         self.weaponframe = 0;
  929.         self.items = self.items | IT_ROCKETS;
  930.     }
  931.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  932.     {
  933.         self.currentammo = self.ammo_rockets;
  934.         self.weaponmodel = "progs/v_rock2.mdl";
  935.         self.weaponframe = 0;
  936.         self.items = self.items | IT_ROCKETS;
  937.     }
  938.     else if (self.weapon == IT_LIGHTNING)
  939.     {
  940.         self.currentammo = self.ammo_cells;
  941.         self.weaponmodel = "progs/v_light.mdl";
  942.         self.weaponframe = 0;
  943.         self.items = self.items | IT_CELLS;
  944.     }
  945.     else
  946.     {
  947.         self.currentammo = 0;
  948.         self.weaponmodel = "";
  949.         self.weaponframe = 0;
  950.     }
  951. };
  952.  
  953. float() W_BestWeapon =
  954. {
  955.     local   float   it;
  956.     
  957.     it = self.items;
  958.  
  959.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  960.         return IT_LIGHTNING;
  961.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  962.         return IT_SUPER_NAILGUN;
  963.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  964.         return IT_SUPER_SHOTGUN;
  965.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  966.         return IT_NAILGUN;
  967.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  968.         return IT_SHOTGUN;
  969.         
  970. /*
  971.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  972.         return IT_ROCKET_LAUNCHER;
  973.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  974.         return IT_GRENADE_LAUNCHER;
  975.  
  976. */
  977.  
  978.     return IT_AXE;
  979. };
  980.  
  981. float() W_CheckNoAmmo =
  982. {
  983.     if (self.currentammo > 0)
  984.         return TRUE;
  985.  
  986.     if (self.weapon == IT_AXE)
  987.         return TRUE;
  988.     
  989.     self.weapon = W_BestWeapon ();
  990.  
  991.     W_SetCurrentAmmo ();
  992.     
  993. // drop the weapon down
  994.     return FALSE;
  995. };
  996.  
  997. /*
  998. ============
  999. W_Attack
  1000.  
  1001. An attack impulse can be triggered now
  1002. ============
  1003. */
  1004. void()  player_axe1;
  1005. void()  player_axeb1;
  1006. void()  player_axec1;
  1007. void()  player_axed1;
  1008. void()  player_shot1;
  1009. void()  player_nail1;
  1010. void()  player_light1;
  1011. void()  player_rocket1;
  1012.  
  1013. void() W_Attack =
  1014. {
  1015.     local   float   r;
  1016.  
  1017.     if (!W_CheckNoAmmo ())
  1018.         return;
  1019.  
  1020.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  1021.     self.show_hostile = time + 1;   // wake monsters up
  1022.  
  1023.     if (self.weapon == IT_AXE)
  1024.     {
  1025.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1026.         r = random();
  1027.         if (r < 0.25)
  1028.             player_axe1 ();
  1029.         else if (r<0.5)
  1030.             player_axeb1 ();
  1031.         else if (r<0.75)
  1032.             player_axec1 ();
  1033.         else
  1034.             player_axed1 ();
  1035.         self.attack_finished = time + 0.5;
  1036.     }
  1037.     else if (self.weapon == IT_SHOTGUN)
  1038.     {
  1039.         player_shot1 ();
  1040.         W_FireShotgun ();
  1041.         self.attack_finished = time + 0.5;
  1042.     }
  1043.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1044.     {
  1045.         player_shot1 ();
  1046.         W_FireSuperShotgun ();
  1047.         self.attack_finished = time + 0.7;
  1048.     }
  1049.     else if (self.weapon == IT_NAILGUN)
  1050.     {
  1051.         player_nail1 ();
  1052.     }
  1053.     else if (self.weapon == IT_SUPER_NAILGUN)
  1054.     {
  1055.         player_nail1 ();
  1056.     }
  1057.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1058.     {
  1059.         player_rocket1();
  1060.         W_FireGrenade();
  1061.         self.attack_finished = time + 0.6;
  1062.     }
  1063.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1064.     {
  1065.         player_rocket1();
  1066.         W_FireRocket();
  1067.         self.attack_finished = time + 0.8;
  1068.     }
  1069.     else if (self.weapon == IT_LIGHTNING)
  1070.     {
  1071.         player_light1();
  1072.         self.attack_finished = time + 0.1;
  1073.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1074.     }
  1075. };
  1076.  
  1077. /*
  1078. ============
  1079. W_ChangeWeapon
  1080.  
  1081. ============
  1082. */
  1083. void() W_ChangeWeapon =
  1084. {
  1085.     local   float   it, am, fl;
  1086.     
  1087.     it = self.items;
  1088.     am = 0;
  1089.     
  1090.     if (self.impulse == 1)
  1091.     {
  1092.         fl = IT_AXE;
  1093.     }
  1094.     else if (self.impulse == 2)
  1095.     {
  1096.         fl = IT_SHOTGUN;
  1097.         if (self.ammo_shells < 1)
  1098.             am = 1;
  1099.     }
  1100.     else if (self.impulse == 3)
  1101.     {
  1102.         fl = IT_SUPER_SHOTGUN;
  1103.         if (self.ammo_shells < 2)
  1104.             am = 1;
  1105.     }               
  1106.     else if (self.impulse == 4)
  1107.     {
  1108.         fl = IT_NAILGUN;
  1109.         if (self.ammo_nails < 1)
  1110.             am = 1;
  1111.     }
  1112.     else if (self.impulse == 5)
  1113.     {
  1114.         fl = IT_SUPER_NAILGUN;
  1115.         if (self.ammo_nails < 2)
  1116.             am = 1;
  1117.     }
  1118.     else if (self.impulse == 6)
  1119.     {
  1120.         fl = IT_GRENADE_LAUNCHER;
  1121.         if (self.ammo_rockets < 1)
  1122.             am = 1;
  1123.     }
  1124.     else if (self.impulse == 7)
  1125.     {
  1126.         fl = IT_ROCKET_LAUNCHER;
  1127.         if (self.ammo_rockets < 1)
  1128.             am = 1;
  1129.     }
  1130.     else if (self.impulse == 8)
  1131.     {
  1132.         fl = IT_LIGHTNING;
  1133.         if (self.ammo_cells < 1)
  1134.             am = 1;
  1135.     }
  1136.  
  1137.     self.impulse = 0;
  1138.     
  1139.     if (!(self.items & fl))
  1140.     {       // don't have the weapon or the ammo
  1141.         sprint (self, "no weapon.\n");
  1142.         return;
  1143.     }
  1144.     
  1145.     if (am)
  1146.     {       // don't have the ammo
  1147.         sprint (self, "not enough ammo.\n");
  1148.         return;
  1149.     }
  1150.  
  1151. //
  1152. // set weapon, set ammo
  1153. //
  1154.     self.weapon = fl;               
  1155.     W_SetCurrentAmmo ();
  1156. };
  1157.  
  1158. /*
  1159. ============
  1160. CheatCommand
  1161. ============
  1162. */
  1163. void() CheatCommand =
  1164. {
  1165.     if (deathmatch || coop)
  1166.         return;
  1167.  
  1168.     self.ammo_rockets = 100;
  1169.     self.ammo_nails = 200;
  1170.     self.ammo_shells = 100;
  1171.     self.items = self.items | 
  1172.         IT_AXE |
  1173.         IT_SHOTGUN |
  1174.         IT_SUPER_SHOTGUN |
  1175.         IT_NAILGUN |
  1176.         IT_SUPER_NAILGUN |
  1177.         IT_GRENADE_LAUNCHER |
  1178.         IT_ROCKET_LAUNCHER |
  1179.         IT_KEY1 | IT_KEY2;
  1180.  
  1181.     self.ammo_cells = 200;
  1182.     self.items = self.items | IT_LIGHTNING;
  1183.  
  1184.     self.weapon = IT_ROCKET_LAUNCHER;
  1185.     self.impulse = 0;
  1186.     W_SetCurrentAmmo ();
  1187. };
  1188.  
  1189. /*
  1190. ============
  1191. CycleWeaponCommand
  1192.  
  1193. Go to the next weapon with ammo
  1194. ============
  1195. */
  1196. void() CycleWeaponCommand =
  1197. {
  1198.     local   float   it, am;
  1199.     
  1200.     it = self.items;
  1201.     self.impulse = 0;
  1202.     
  1203.     while (1)
  1204.     {
  1205.         am = 0;
  1206.  
  1207.         if (self.weapon == IT_LIGHTNING)
  1208.         {
  1209.             self.weapon = IT_AXE;
  1210.         }
  1211.         else if (self.weapon == IT_AXE)
  1212.         {
  1213.             self.weapon = IT_SHOTGUN;
  1214.             if (self.ammo_shells < 1)
  1215.                 am = 1;
  1216.         }
  1217.         else if (self.weapon == IT_SHOTGUN)
  1218.         {
  1219.             self.weapon = IT_SUPER_SHOTGUN;
  1220.             if (self.ammo_shells < 2)
  1221.                 am = 1;
  1222.         }               
  1223.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1224.         {
  1225.             self.weapon = IT_NAILGUN;
  1226.             if (self.ammo_nails < 1)
  1227.                 am = 1;
  1228.         }
  1229.         else if (self.weapon == IT_NAILGUN)
  1230.         {
  1231.             self.weapon = IT_SUPER_NAILGUN;
  1232.             if (self.ammo_nails < 2)
  1233.                 am = 1;
  1234.         }
  1235.         else if (self.weapon == IT_SUPER_NAILGUN)
  1236.         {
  1237.             self.weapon = IT_GRENADE_LAUNCHER;
  1238.             if (self.ammo_rockets < 1)
  1239.                 am = 1;
  1240.         }
  1241.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1242.         {
  1243.             self.weapon = IT_ROCKET_LAUNCHER;
  1244.             if (self.ammo_rockets < 1)
  1245.                 am = 1;
  1246.         }
  1247.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1248.         {
  1249.             self.weapon = IT_LIGHTNING;
  1250.             if (self.ammo_cells < 1)
  1251.                 am = 1;
  1252.         }
  1253.     
  1254.         if ( (self.items & self.weapon) && am == 0)
  1255.         {
  1256.             W_SetCurrentAmmo ();
  1257.             return;
  1258.         }
  1259.     }
  1260.  
  1261. };
  1262.  
  1263. /*
  1264. ============
  1265. ServerflagsCommand
  1266.  
  1267. Just for development
  1268. ============
  1269. */
  1270. void() ServerflagsCommand =
  1271. {
  1272.     serverflags = serverflags * 2 + 1;
  1273. };
  1274.  
  1275. void() QuadCheat =
  1276. {
  1277.     if (deathmatch || coop)
  1278.         return;
  1279.     self.super_time = 1;
  1280.     self.super_damage_finished = time + 30;
  1281.     self.items = self.items | IT_QUAD;
  1282.     dprint ("quad cheat\n");
  1283. };
  1284.  
  1285. /*
  1286. ============
  1287. ImpulseCommands
  1288.  
  1289. ============
  1290. */
  1291. void() ImpulseCommands =
  1292. {
  1293.     if (self.impulse >= 1 && self.impulse <= 8)
  1294.         W_ChangeWeapon ();
  1295.  
  1296.     if (self.impulse == 9)
  1297.         CheatCommand ();
  1298.     if (self.impulse == 10)
  1299.         CycleWeaponCommand ();
  1300.     if (self.impulse == 11)
  1301.         ServerflagsCommand ();
  1302.     
  1303.     // dhm - Throw that doggie a bone!
  1304.     if (self.impulse == 20)
  1305.         {    
  1306.         if (time < self.attack_finished)
  1307.             return;
  1308.         sprint (self, "Here doggie!\n");
  1309.         W_LaunchBone ();
  1310.         }
  1311.      //dhm - end
  1312.     
  1313.     if (self.impulse == 255)
  1314.         QuadCheat ();
  1315.         
  1316.     self.impulse = 0;
  1317. };
  1318.  
  1319. /*
  1320. ============
  1321. W_WeaponFrame
  1322.  
  1323. Called every frame so impulse events can be handled as well as possible
  1324. ============
  1325. */
  1326. void() W_WeaponFrame =
  1327. {
  1328.     if (time < self.attack_finished)
  1329.         return;
  1330.  
  1331.     ImpulseCommands ();
  1332.     
  1333. // check for attack
  1334.     if (self.button0)
  1335.     {
  1336.         SuperDamageSound ();
  1337.         W_Attack ();
  1338.     }
  1339. };
  1340.  
  1341. /*
  1342. ========
  1343. SuperDamageSound
  1344.  
  1345. Plays sound if needed
  1346. ========
  1347. */
  1348. void() SuperDamageSound =
  1349. {
  1350.     if (self.super_damage_finished > time)
  1351.     {
  1352.         if (self.super_sound < time)
  1353.         {
  1354.             self.super_sound = time + 1;
  1355.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1356.         }
  1357.     }
  1358.     return;
  1359. };
  1360.  
  1361.  
  1362.